/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hitechbangla.fctu.form;

import com.hitechbangla.fctu.base.GameScene;
import com.hitechbangla.fctu.base.Location;
import com.hitechbangla.fctu.base.aircraft.Aircraft;
import com.hitechbangla.fctu.base.aircraft.AircraftState;
import com.hitechbangla.fctu.base.aircraft.AircraftType;
import com.hitechbangla.fctu.base.base.Base;
import fctu.simulator.HTB_MAIN;
import java.util.Timer;
import java.util.TimerTask;

/**
 *
 * @author Asus
 */
public class LaunchAircraft extends javax.swing.JFrame {

    /**
     * Creates new form LaunchAircraft
     */
    private GameScene gameScene;
    
    public LaunchAircraft(GameScene gameScene) 
    {
	this.gameScene = gameScene;
	initComponents();	
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jComboBoxBaseName = new javax.swing.JComboBox();
        jTextFieldCallSign = new javax.swing.JTextField();
        jTextFieldGroupName = new javax.swing.JTextField();
        jComboAlertnes = new javax.swing.JComboBox();
        jComboAircraftType = new javax.swing.JComboBox();
        jButtonOk = new javax.swing.JButton();
        jButtonCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(250, 300));

        jLabel1.setText("Base Name:");

        jLabel2.setText("Aircraft Type:");

        jLabel3.setText("Callsign:");

        jLabel4.setText("Group Name:");

        jLabel6.setText("Alertness:");

        if(gameScene == null){
            //System.out.println("From Launch Ac game scene is null");
        }
        jComboBoxBaseName.setModel(new javax.swing.DefaultComboBoxModel(gameScene.getBaseListStringArray()));
        jComboBoxBaseName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxBaseNameActionPerformed(evt);
            }
        });

        jComboAlertnes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Aletrness - 1", "Alertness - 2", "Alertness - 3", "Alertness - 4" }));
        jComboAlertnes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboAlertnesActionPerformed(evt);
            }
        });

        jComboAircraftType.setModel(new javax.swing.DefaultComboBoxModel(gameScene.getAirCraftTypeStringArray()));

        jButtonOk.setText("Ok");
        jButtonOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOkActionPerformed(evt);
            }
        });

        jButtonCancel.setText("Cancel");
        jButtonCancel.setToolTipText("");
        jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jComboBoxBaseName, 0, 68, Short.MAX_VALUE)
                            .addComponent(jTextFieldGroupName)
                            .addComponent(jTextFieldCallSign)
                            .addComponent(jComboAlertnes, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jComboAircraftType, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButtonOk, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonCancel)))
                .addContainerGap(42, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jComboBoxBaseName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jComboAlertnes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jComboAircraftType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldCallSign, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldGroupName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCancel)
                    .addComponent(jButtonOk))
                .addGap(79, 79, 79))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxBaseNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxBaseNameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBoxBaseNameActionPerformed

    private void jComboAlertnesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboAlertnesActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboAlertnesActionPerformed

    private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
        // TODO add your handling code here:
	disposeWindow();
    }//GEN-LAST:event_jButtonCancelActionPerformed

    private void jButtonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOkActionPerformed
        // TODO add your handling code here:
	
	
	
	TimerTask timerTask = new TimerTask() {

	     @Override
	    public void run() {
		//throw new UnsupportedOperationException("Not supported yet.");
		Base base = gameScene.baseList.get(jComboBoxBaseName.getSelectedIndex());
		AircraftState state = new AircraftState(jTextFieldCallSign.getText(),new Location(base.getLocation().getX() , base.getLocation().getY(), 0), base.getBaseType().getTakeOfHeading(), (float)200,1000);
		AircraftType type = gameScene.airCraftTypeList.get(jComboAircraftType.getSelectedIndex());
		Aircraft ac = new Aircraft(state, type);
		gameScene.airCraftList.add(ac);
		 //System.out.println("From Launch Aircraft : Programming is reallly awesome !!!");
		gameScene.HTBParent.repaint();
	    }
	};
	Timer timer = new Timer();

	int delay = 1;
	switch(jComboAlertnes.getSelectedIndex()){
	case 0:
	    delay = 2;
	break;
	case 1:
	    delay = 3;
	    break;
	case 2:
	    delay = 4;
	    break;
	case 3 :
	    delay = 5;
	    break;
	}
	timer.schedule(timerTask, delay * 1000);
	disposeWindow();
    }//GEN-LAST:event_jButtonOkActionPerformed

    void disposeWindow(){
	this.setVisible(false);
	this.dispose();;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
	/* Set the Nimbus look and feel */
	//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
	 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
	 */
	try {
	    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
		if ("Nimbus".equals(info.getName())) {
		    javax.swing.UIManager.setLookAndFeel(info.getClassName());
		    break;
		}
	    }
	} catch (ClassNotFoundException ex) {
	    java.util.logging.Logger.getLogger(LaunchAircraft.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	} catch (InstantiationException ex) {
	    java.util.logging.Logger.getLogger(LaunchAircraft.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	} catch (IllegalAccessException ex) {
	    java.util.logging.Logger.getLogger(LaunchAircraft.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	} catch (javax.swing.UnsupportedLookAndFeelException ex) {
	    java.util.logging.Logger.getLogger(LaunchAircraft.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	}
	//</editor-fold>

	/* Create and display the form */
	java.awt.EventQueue.invokeLater(new Runnable() {
	    public void run() {
		new LaunchAircraft(null).setVisible(true);
	    }
	});
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancel;
    private javax.swing.JButton jButtonOk;
    private javax.swing.JComboBox jComboAircraftType;
    private javax.swing.JComboBox jComboAlertnes;
    private javax.swing.JComboBox jComboBoxBaseName;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField jTextFieldCallSign;
    private javax.swing.JTextField jTextFieldGroupName;
    // End of variables declaration//GEN-END:variables
}
